package com.lza.mybatiyPlus;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;

public class CodeGenerator {
    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("李钊澳");
        gc.setOpen(false);
        gc.setFileOverride(false);//重新生成是否覆盖文件
        gc.setServiceName("%sService");//以studentsevice,userservice形式生成
        gc.setIdType(IdType.AUTO);//设置主键生成策列，自动增长
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/phonepk?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("1234");
        mpg.setDataSource(dsc);


        // 包配置
        PackageConfig pc = new PackageConfig();
        //pc.setModuleName("exam");
        pc.setParent("com.lza.phone");
        //相当于生成 com.lza.plustest.exam
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setService("service");
        pc.setController("controller");
        pc.setServiceImpl("service.impl");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        //设置需要生成的表(奇怪，我什么都不加她反而帮我创建所有表)
        /* strategy.setInclude("score","teacher","admin");*/
        //strategy.setNaming(NamingStrategy.underline_to_camel);//实体类名称驼峰命名
        //strategy.setColumnNaming(NamingStrategy.underline_to_camel);//列明名称驼峰命名
        //strategy.setInclude("phone","battery","camera","performance","screen","size","soc");//设置要映射的表名
        strategy.setInclude("socSort");//设置要映射的表名
        strategy.setEntityLombokModel(true);//自动lombok
        strategy.setRestControllerStyle(true);//使用RestController风格
        mpg.setStrategy(strategy);
        mpg.execute();
    }

}

